package com.example.elderlycare.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.elderlycare.dao.entity.Employee;
import com.example.elderlycare.dao.entity.TrainEmployee;
import com.example.elderlycare.dao.mapper.TrainEmployeeMapper;
import com.example.elderlycare.service.TrainEmployeeService;
import com.example.elderlycare.service.entity.QueryListResponseBody;
import com.example.elderlycare.service.entity.TrainEmployeeItem;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class TrainEmployeeServiceImpl extends ServiceImpl<TrainEmployeeMapper, TrainEmployee> implements TrainEmployeeService {
    @Resource
    TrainEmployeeMapper trainEmployeeMapper;

    @Override
    public QueryListResponseBody<TrainEmployeeItem> queryTrainEmployeeList(Map<String, Object> params) {
        QueryListResponseBody.QueryListResponseBodyBuilder<TrainEmployeeItem> queryListResponseBodyBuilder = QueryListResponseBody.builder();
        Integer count = trainEmployeeMapper.queryTrainEmployeeCount(params);
        queryListResponseBodyBuilder.total(count);
        List<TrainEmployeeItem> items = new ArrayList<>();
        List<Employee> result = trainEmployeeMapper.queryTrainEmployeeList(params);
        result.forEach(item -> {
            TrainEmployeeItem.TrainEmployeeItemBuilder trainEmployeeItemBuilder = TrainEmployeeItem.builder();
            trainEmployeeItemBuilder.name(item.getName()).id(item.getId());
            items.add(trainEmployeeItemBuilder.build());
        });
        queryListResponseBodyBuilder.items(items);
        return queryListResponseBodyBuilder.build();
    }
}
